<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/5/25
 * 多任务 消费者类
 */
namespace app\job;

use think\queue\Job;

class MultiTask{
    //task1
    public function task1(Job $job, $data){
        $isDone = $this->doTask1($data);
        if($isDone){
            $job->delete();
            print("the task1 is delete done\n");
        }else{
            if($job->attempts() > 3){
                $job->delete();
            }else{ //重发任务
                $job->release(2);//延迟2秒重发
            }
        }
    }

    //task2
    public function task2(Job $job, $data){
        $isDone = $this->doTask2($data);
        if($isDone){
            $job->delete();
            print("the task2 is delete done\n");
        }else{
            if($job->attempts() > 3){
                $job->delete();
            }else{
                $job->release(2);//延迟2秒重发
            }
        }
    }

    //执行task1
    private function doTask1($data){
        echo "the task1 is done\n";
        return true;
    }

    //执行task2
    private function doTask2($data){
        echo "the task2 is done\n";
        return true;
    }
}